<template>
    <article class="form-other-config">
        <el-form ref="otherFormRef" :model="formData" :rules="rules" label-width="auto">
            <h4 class="form-title">高级设置</h4>
            <el-form-item prop="submit_settings.limit_type">
                <template #label>
                    <span> <span class="require-icon">*</span> 提交次数限制</span>
                </template>
                <!-- 注意兼容历史数据-todo -->
                <el-radio-group
                    v-model="formData.submit_settings.limit_type"
                    class="form-setting-num"
                    :disabled="isViewDisabled"
                    @change="changeNum">
                    <el-radio :label="3">
                        每人最多提交<el-input-number
                            v-model="formData.submit_settings.limit_value"
                            :min="1"
                            :max="99"
                            :disabled="isViewDisabled || formData.submit_settings.limit_type != 3"
                            placeholder=""
                            :controls="false" />次
                    </el-radio>
                    <el-radio :label="2">不限次数</el-radio>
                </el-radio-group>
            </el-form-item>
            <el-form-item label="收集数量限制" prop="submit_settings.collect_type">
                <el-checkbox
                    v-model="formData.submit_settings.collect_type"
                    class="form-setting-num"
                    :disabled="isViewDisabled"
                    @change="changeLimit">
                    <div class="d-flex form-setting-center">
                        <span> 收集 </span>
                        <el-input-number
                            v-model="formData.submit_settings.collect_limit"
                            :min="1"
                            :max="99999999"
                            class="collect-limit-input"
                            :disabled="isViewDisabled || !formData.submit_settings.collect_type"
                            placeholder="请输入"
                            :controls="false" />
                        <span>份问卷后，收集表活动自动结束</span>
                    </div>
                </el-checkbox>
                <div class="form-alert-tips">若不勾选，则不限制收集数量。</div>
            </el-form-item>
            <el-form-item label="修改提交结果" prop="submit_settings.is_allow_change">
                <el-checkbox
                    v-model="formData.submit_settings.is_allow_change"
                    :true-label="2"
                    :false-label="1"
                    :disabled="isViewDisabled">
                    允许填写人修改结果
                </el-checkbox>
                <div class="form-alert-tips">勾选后，用户提交表单后可修改填写结果再次提交。</div>
            </el-form-item>
            <el-form-item
                label="自动打标签"
                :rules="{
                    required: formData.tags_enter_enable || formData.tags_submit_enable,
                    trigger: 'blur',
                    validator: validatorTag(index)
                }">
                <div class="form-batch-switch">
                    <el-checkbox v-model="formData.tags_enter_enable" :disabled="isViewDisabled"></el-checkbox>
                    <span>浏览表单打标签</span>
                </div>
                <div class="form-choose-tags">
                    <div v-if="formData.tags_enter_enable">
                        <el-button
                            v-if="formData.tags_enter_enable"
                            :icon="Plus"
                            class="form-tag-btn"
                            :disabled="isViewDisabled"
                            @click="openBatchLabel('enter')">
                            添加标签
                        </el-button>
                        <span v-if="formData.tags_enter_enable" class="tag-span"
                            >已选择标签<em>{{ formData?.tags_enter?.length || 0 }}</em
                            >个</span
                        >
                    </div>
                    <DetailTags
                        v-show="formData.tags_enter_enable"
                        v-model:tags="formData.tags_enter"
                        :disabled="isViewDisabled"
                        @open="openBatchLabel('enter')" />
                </div>
                <div class="form-batch-switch">
                    <el-checkbox v-model="formData.tags_submit_enable" :disabled="isViewDisabled"></el-checkbox>
                    <span>提交表单打标签</span>
                </div>
                <div class="form-choose-tags">
                    <div v-if="formData.tags_submit_enable">
                        <el-button
                            v-if="formData.tags_submit_enable"
                            :icon="Plus"
                            :disabled="isViewDisabled"
                            class="form-tag-btn"
                            @click="openBatchLabel('submit')">
                            添加标签
                        </el-button>
                        <span v-if="formData.tags_submit_enable" class="tag-span"
                            >已选择标签<em>{{ formData?.tags_submit?.length || 0 }}</em
                            >个</span
                        >
                    </div>
                    <DetailTags
                        v-show="formData.tags_submit_enable"
                        v-model:tags="formData.tags_submit"
                        :disabled="isViewDisabled"
                        @open="openBatchLabel('submit')" />
                </div>
            </el-form-item>
            <el-divider />
            <h4 class="form-title">提交结果页设置</h4>
            <el-form-item label="结束语">
                <el-input
                    v-model="formData.conclusion"
                    type="textarea"
                    maxlength="200"
                    resize="none"
                    style="width: 400px"
                    :rows="5"
                    show-word-limit
                    placeholder="请输入结束语"
                    :disabled="isViewDisabled" />
            </el-form-item>
            <el-form-item label="图片广告">
                <el-upload
                    v-model:file="uploadList"
                    v-loading="imgLoading"
                    :http-request="handleHttpRequest"
                    :before-upload="onBeforeUpload"
                    :show-file-list="false"
                    accept=".jpg,.png,.JPEG"
                    class="chen"
                    :disabled="isViewDisabled">
                    <div v-if="uploadList[0]" class="share_file share_file_img">
                        <img :src="uploadList[0].url" />
                        <div class="upload-content">
                            <div class="upload-icon" @click.stop="dialogPreviewImgVisible = true">
                                <el-icon>
                                    <zoom-in />
                                </el-icon>
                            </div>
                            <div v-if="!isViewDisabled" class="upload-icon" @click.stop="uploadList.splice(0, 1)">
                                <el-icon>
                                    <Delete />
                                </el-icon>
                            </div>
                        </div>
                    </div>
                    <div v-else class="share_file">
                        <el-icon>
                            <Plus />
                        </el-icon>
                    </div>
                </el-upload>
                <div class="tip">图片支持png、jpg、jpeg格式，大小10M以内，建议尺寸200*200px。</div>
            </el-form-item>
            <el-form-item label="引导扫码">
                <el-checkbox v-model="formData.submit_settings.redirect.enable" :disabled="isViewDisabled">
                    引导扫码添加员工/群聊
                </el-checkbox>
                <template v-if="formData.submit_settings.redirect.enable">
                    <el-form-item style="margin-bottom: 10px" prop="submit_settings.redirect.code_scanning_guidance">
                        <template #label>
                            <span> <span class="require-icon">*</span> 扫码引导</span>
                        </template>
                        <el-input
                            v-model.trim="formData.submit_settings.redirect.code_scanning_guidance"
                            maxlength="15"
                            :disabled="isViewDisabled || !FormRedirect.enable"
                            show-word-limit
                            placeholder="长按识别二维码添加客服" />
                    </el-form-item>
                    <el-form-item label="添加内容" prop="submit_settings.redirect.submit_redirect_type">
                        <template #label>
                            <span> <span class="require-icon">*</span> 添加内容</span>
                        </template>
                        <el-radio-group
                            v-model="formData.submit_settings.redirect.submit_redirect_type"
                            :disabled="isViewDisabled || !FormRedirect.enable"
                            @change="handleRedircetTypeChange">
                            <el-radio :label="1">添加员工</el-radio>
                            <el-radio :label="2">添加群聊</el-radio>
                        </el-radio-group>
                        <div v-if="FormRedirect.group_id?.group_id" class="redirect-group-content">
                            <div class="tip">只需要选择一个群聊作为初始群聊，群满可以自动裂变出新的群聊</div>
                            <div class="redirect-group-content__item">
                                <div>
                                    <img :src="FormRedirect.group_id.avatar" alt="" />
                                </div>
                                <div class="group_name_text">群名称：{{ FormRedirect.group_id.name }}</div>
                                <div class="group_name_qunzhu" :title="FormRedirect.group_id.manager?.name">
                                    群主：{{ FormRedirect.group_id.manager?.name }}
                                </div>
                            </div>
                        </div>
                        <div>
                            <div v-if="FormRedirect.submit_redirect_type === 1">
                                <el-button
                                    :disabled="isViewDisabled || !FormRedirect.enable"
                                    :icon="Plus"
                                    class="form-tag-btn"
                                    @click="handleDepartClick"
                                    >选择员工</el-button
                                >
                                <span class="tag-span"
                                    >已选员工<em>{{ FormRedirect?.work_user_welcome?.work_user_ids?.length || 0 }}</em
                                    >个</span
                                >
                            </div>
                            <el-button
                                v-else
                                :disabled="isViewDisabled || !FormRedirect.enable"
                                :icon="Plus"
                                class="form-tag-btn"
                                @click="handleGroupClick"
                                >选择群聊</el-button
                            >
                        </div>
                        <DetailUserTags
                            v-if="FormRedirect.work_user_welcome.work_user_ids?.length"
                            v-model:tags="FormRedirect.work_user_welcome.work_user_ids"
                            :disabled="isViewDisabled"
                            class="custom-user-tags"
                            @open="handleDepartClick" />
                    </el-form-item>
                    <el-form-item
                        v-show="FormRedirect.enable && FormRedirect.submit_redirect_type === 1"
                        style="margin-top: 20px"
                        prop="submit_settings.redirect.welcome">
                        <template #label>
                            <span> <span class="require-icon">*</span> 欢迎语设置</span>
                        </template>
                        <Welcome
                            ref="WelcomeRef"
                            :disabled="isViewDisabled"
                            :max-num="9"
                            :input-content-tabs="[1, 2, 5, 6]"
                            :show-material-tabs="['1', '2', '3', '4', '5', '7', '9', '10', '11']"
                            :store-customers="false"
                            :fission="false"
                            :material-content-data="defaultMaterialContentData"
                            :input-content-data="formData.submit_settings.redirect.welcome"
                            :operation-list="isViewDisabled ? [] : [1]"
                            :is-render-preview="false"
                            :is-render-flag="false"
                            :is-rules="false"
                            label-width="auto"
                            @change="changeWelcomeTest" />
                    </el-form-item>
                </template>
            </el-form-item>
            <el-divider />
            <h4 class="form-title">分享设置</h4>
            <el-form-item prop="share_setting.link_img_url">
                <template #label>
                    <span> <span class="require-icon">*</span> 链接封面</span>
                </template>
                <el-upload
                    v-model:file="fileList"
                    v-loading="shareImgLoading"
                    :http-request="handleShareHttpRequest"
                    :before-upload="onBeforeUpload2"
                    :show-file-list="false"
                    accept=".jpg,.png,.JPEG"
                    :disabled="isViewDisabled"
                    class="chen">
                    <div v-if="fileList[0]" class="share_file share_file_img">
                        <img :src="fileList[0].url" />
                        <div class="upload-content">
                            <div class="upload-icon" @click.stop="dialogPreviewVisible = true">
                                <el-icon>
                                    <zoom-in />
                                </el-icon>
                            </div>
                            <div v-if="!isViewDisabled" class="upload-icon" @click.stop="fileList.splice(0, 1)">
                                <el-icon>
                                    <Delete />
                                </el-icon>
                            </div>
                        </div>
                    </div>
                    <div v-else class="share_file">
                        <el-icon>
                            <Plus />
                        </el-icon>
                    </div>
                </el-upload>
                <div class="tip">图片支持png、jpg、jpeg格式，大小2M以内，建议尺寸200*200px。</div>
            </el-form-item>
            <el-form-item prop="share_setting.link_title">
                <template #label>
                    <span> <span class="require-icon">*</span> 链接标题</span>
                </template>
                <el-input
                    v-model="formData.share_setting.link_title"
                    maxlength="15"
                    style="width: 400px"
                    :disabled="isViewDisabled"
                    show-word-limit
                    placeholder="请输入标题" />
            </el-form-item>
            <el-form-item label="链接描述">
                <el-input
                    v-model="formData.share_setting.link_describe"
                    style="width: 400px"
                    maxlength="50"
                    :disabled="isViewDisabled"
                    show-word-limit
                    placeholder="请输入描述" />
            </el-form-item>
        </el-form>
        <el-dialog v-model="dialogPreviewVisible">
            <img w-full :src="fileList[0].url" style="width: 100%" />
        </el-dialog>
        <el-dialog v-model="dialogPreviewImgVisible">
            <img w-full :src="uploadList[0].url" style="width: 100%" />
        </el-dialog>
        <el-affix v-if="currentStep === 3" ref="affixRef" :offset="120" z-index="2">
            <div class="preview_config">
                <Phone :label="FormRedirect.title">
                    <div class="header">
                        <el-icon>
                            <close-bold />
                        </el-icon>
                        <!-- <h3>页面标题</h3> -->
                    </div>
                    <div class="preview-phone">
                        <div class="submit_tip">
                            <img src="@/assets/image/content/submit-success.png" alt="" class="submit-icon" />
                            <div class="submit-text">提交成功</div>
                            <div class="submit-end-text">{{ formData.conclusion }}</div>
                        </div>
                        <img class="custom-img" :src="uploadList[0]?.url" alt="" />
                        <div v-show="formData.submit_settings.redirect.enable" class="qr_code">
                            <img src="@/assets/image/normal_qrcode.png" alt="" />
                            <div class="tip">
                                {{ FormRedirect.code_scanning_guidance || '长按识别二维码添加客服' }}
                            </div>
                        </div>
                    </div>
                </Phone>
            </div>
        </el-affix>
    </article>
    <ZwBatchLabel ref="BatchLabelRef" @save="getTagsFun"></ZwBatchLabel>
    <ZWDepart ref="DepartRef" :type="1" @submit="getDepart"></ZWDepart>
    <GroupChart ref="GroupChartRef" :is-not-name-disabled="true" @submit="getGroup" />
</template>
<script lang="ts" setup>
import { reactive, ref, defineExpose, computed, onMounted, inject, h } from 'vue';
import { ElMessage, ElMessageBox } from 'element-plus';
import { initMaterialData } from '@/utils/utils';
import { uploadFile2 } from '@/api/common';
import { handleOtherConfig, handleOtherConfigToView } from './utils/DataProcessing';
import { useRoute } from 'vue-router';
import ZWDepart from '@/components/ZWDepart1.0.vue';
import Welcome from '@/components/zw/materialContent1.0/index.vue';
import GroupChart from '@/components/chart/GroupChart.vue';
import DetailTags from './DetailTags.vue';
import DetailUserTags from './DetailUserTags.vue';
import Phone from '@/components/zw/phonePreview1.0/activityPhonePreview/index.vue';
import { Plus } from '@element-plus/icons-vue';
import _ from 'lodash';

const route: any = useRoute();
const currentStep = inject('currentStep');
const routeType = computed(() => {
    // 跳转类型
    return route.query.type;
});
const isViewDisabled = computed(() => {
    // 查看下禁用
    return routeType.value === 'view';
});
onMounted(() => {
    formData.share_setting.link_img_url =
        'https://static.scrm.keyid.cn/keyid-scrm-server/tmp-file/2022-10-24/Am56aZLebDKrYMjZ1qBU09oWng9d2XxPwVBJ.jpeg';
});

/* ==============================标签============================== */
let BATCH_TYPE = 'enter';
// 打开选择标签弹框
const openBatchLabel = (type: string) => {
    BATCH_TYPE = type;
    BatchLabelRef.value.dialogVisible = true;
    BatchLabelRef.value.title = '批量打标签';
    BatchLabelRef.value.hasConditiion = false;
    BatchLabelRef.value.chooseDataArr.splice(
        0,
        BatchLabelRef.value.chooseDataArr.length,
        ...formData[`tags_${BATCH_TYPE}`]
    );
    // BatchLabelRef.value.chooseDataArr = [...formData[`tags_${BATCH_TYPE}`]];
};

/**获取当前选中的标签*/
const getTagsFun = async (val?: any) => {
    formData[`tags_${BATCH_TYPE}`] = [...val.data];
};
const BatchLabelRef = ref();
/* ==============================标签============================== */

/* ==============================选择员工/群聊============================== */
// 员工
const DepartRef = ref();
const handleDepartClick = () => {
    DepartRef.value.selectedMember = FormRedirect.value.work_user_welcome.work_user_ids
        ? [...FormRedirect.value.work_user_welcome.work_user_ids]
        : [];
    DepartRef.value.departVisble = true;
};
const getDepart = (val: any) => {
    formData.submit_settings.redirect.work_user_welcome.work_user_ids = [...val];
    validateField('submit_settings.redirect.submit_redirect_type');
};
const handleRedircetTypeChange = (val: any) => {
    const REIRECT_DATA = formData.submit_settings.redirect;
    REIRECT_DATA.work_user_welcome.work_user_ids.splice(0, REIRECT_DATA.work_user_welcome.work_user_ids.length);
    REIRECT_DATA.group_id = {};
};

// 群聊
const GroupChartRef = ref();
const handleGroupClick = () => {
    GroupChartRef.value.appDialog.visible = true;
    GroupChartRef.value.single = true;
};

const getGroup = (val: any) => {
    formData.submit_settings.redirect.group_id = { ...val };
    validateField('submit_settings.redirect.submit_redirect_type');
};

/* ==============================选择员工/群聊============================== */
/**提交结果页设置======================================= start */
const welcome_info = reactive({});
const dialogPreviewImgVisible = ref(false);
const uploadList = reactive([]);
const imgLoading = ref(false);
const handleHttpRequest = async (file: any) => {
    try {
        imgLoading.value = true;
        const res = await doUpload(file);
        uploadList.splice(0, uploadList.length, res);
        imgLoading.value = false;
    } catch {
        imgLoading.value = false;
    }
};
/**
 * 欢迎语更改内容时回调，实时变更v-model的值
 */
const changeWelcomeTest = (val: any) => {
    Object.assign(welcome_info, val.welcome_info);
    formData.submit_settings.redirect.welcome = val.welcome_info.welcome_text;
};
// 校验欢迎语
const welcomeValidator = (rule: any, value: any, callback: any) => {
    if (formData.submit_settings.redirect.enable && formData.submit_settings.redirect.submit_redirect_type === 1) {
        if (IsEmpty(formData.submit_settings.redirect.welcome)) {
            return callback(new Error('请输入欢迎语'));
        }
    }
    callback();
};
let defaultMaterialContentData = reactive<Array<any>>([]);
/**提交结果页设置======================================= end */
/* 分享设置 */
const fileList = reactive<Array<any>>([]);

// 上传文件
const doUpload = async (file: any) => {
    const params = {
        file: file.file,
        fileName: file.file.name
    };
    const res: any = await uploadFile2(params, null, true);
    return res;
};
const onBeforeUpload = async (file: any) => {
    return new Promise((resolve, reject) => {
        const is2M = file.size / 1024 / 1024 <= 10;

        if (!is2M) {
            ElMessage.warning(`上传的图片最大支持${10}M`);
            return reject(false);
        }

        const acceptImg = ['image/png', 'image/jpg', 'image/jpeg'];
        if (!acceptImg.includes(file.type)) {
            ElMessage.error('图片格式不正确！');
            return reject(false);
        }

        return resolve(true);
    });
};
// todo:后期优化成一个函数
const onBeforeUpload2 = async (file: any) => {
    return new Promise((resolve, reject) => {
        const is2M = file.size / 1024 / 1024 <= 2;

        if (!is2M) {
            ElMessage.warning(`上传的图片最大支持${2}M`);
            return reject(false);
        }

        const acceptImg = ['image/png', 'image/jpg', 'image/jpeg'];
        if (!acceptImg.includes(file.type)) {
            ElMessage.error('图片格式不正确！');
            return reject(false);
        }

        return resolve(true);
    });
};
// 分享图片上传
const shareImgLoading = ref(false);
const handleShareHttpRequest = async (file: any) => {
    try {
        shareImgLoading.value = true;
        const res = await doUpload(file);
        fileList.splice(0, fileList.length, res);
        shareImgLoading.value = false;
        validateField('share_setting.link_img_url');
    } catch {
        shareImgLoading.value = false;
    }
};

/* 分享设置 */

const otherFormRef = ref<any>();
const WelcomeRef = ref<any>();
const formData = reactive<any>({
    tags_enter_enable: false,
    tags_enter: [],
    tags_submit_enable: false,
    tags_submit: [],
    conclusion: '',
    ads: '',
    submit_settings: {
        limit_type: 3,
        limit_value: 1,
        collect_type: false,
        collect_limit: undefined,
        is_allow_change: 1,
        redirect: {
            enable: false,
            title: '',
            code_scanning_guidance: '长按识别二维码添加客服',
            submit_redirect_type: 1,
            welcome: '',
            work_user_welcome: {
                work_user_ids: []
            },
            group_id: {}
        }
    },
    share_setting: {
        disabled: 1,
        link_title: '', //链接标题
        link_describe: '' // 链接描述
    }
});
const FormRedirect = computed(() => {
    return formData.submit_settings?.redirect || {};
});

/* 校验规则 */
const IsEmpty = (value: any) => !value && value !== 0;
// 提交次数限制
const submitLimitValidator = (rule: any, value: any, callback: any) => {
    if (!value) return callback(new Error('请选择提交次数限制'));

    if (value === 3) {
        const limit_value = formData.submit_settings.limit_value;
        if (IsEmpty(limit_value)) return callback(new Error('请输入提交次数'));
    }
    callback();
};
// 收集数量限制
const submitcollectValidator = (rule: any, value: any, callback: any) => {
    if (value) {
        if (IsEmpty(formData.submit_settings.collect_limit)) return callback(new Error('请输入收集数量'));
    }
    callback();
};
// 提交表单跳转页面标题
const redirectEnableValidator = (rule: any, value: any, callback: any) => {
    if (formData.submit_settings.redirect.enable) {
        if (!value) return callback(new Error('请输入页面标题'));
    }
    callback();
};
const redirectEnableGuidanceValidator = (rule: any, value: any, callback: any) => {
    if (formData.submit_settings.redirect.enable) {
        if (!value) return callback(new Error('请输入扫码引导'));
    }
    callback();
};
const redirectTypeValidator = (rule: any, value: any, callback: any) => {
    if (formData.submit_settings.redirect.enable) {
        if (value === 1) {
            if (!FormRedirect.value?.work_user_welcome?.work_user_ids?.length) {
                return callback(new Error('请选择员工'));
            }
        } else {
            if (!FormRedirect.value?.group_id?.group_id) {
                return callback(new Error('请选择群聊'));
            }
        }
    }
    callback();
};
const shareTitleValidator = (rule: any, value: any, callback: any) => {
    if (IsEmpty(value)) return callback(new Error('请输入链接标题'));
    callback();
};

const shareImgUrlValidator = (rule: any, value: any, callback: any) => {
    if (IsEmpty(fileList[0]?.url)) return callback(new Error('请上传链接封面'));
    callback();
};
const rules = reactive({
    'submit_settings.limit_type': [{ require: true, validator: submitLimitValidator }],
    'submit_settings.collect_type': [{ require: true, validator: submitcollectValidator }],
    'submit_settings.redirect.title': [{ require: true, validator: redirectEnableValidator }],
    'submit_settings.redirect.code_scanning_guidance': [{ require: true, validator: redirectEnableGuidanceValidator }],
    'submit_settings.redirect.submit_redirect_type': [{ require: true, validator: redirectTypeValidator }],
    'share_setting.link_title': [{ require: true, validator: shareTitleValidator }],
    'share_setting.link_img_url': [{ require: true, validator: shareImgUrlValidator }],
    'submit_settings.redirect.welcome': [{ require: true, validator: welcomeValidator }]
});
const validatorTag = () => {
    return (rule, value, callback) => {
        if (
            (formData.tags_enter_enable && !formData.tags_enter.length) ||
            (!formData.tags_submit.length && formData.tags_submit_enable)
        ) {
            return callback(new Error('请选择标签'));
        }
        callback();
    };
};

/* 校验规则 */

const getParams = async notValidate => {
    return new Promise((resolve, reject) => {
        if (notValidate) {
            const welcome = {
                is_staff: 0,
                // content: WelcomeRef.value.formData.materialResult.welcome_info.welcome_text,
                // media_content: WelcomeRef.value.formData.materialResult.welcome_info.welcome_material,
                // local_link: WelcomeRef.value.formData.materialResult.welcome_info.welcome_material,
                // local_content: WelcomeRef.value.formData.materialResult.welcome_info.welcome_material,
                welcome_info: welcome_info // 使用欢迎语组件数据
            };
            resolve(handleOtherConfig(formData, fileList, welcome, uploadList));
            return;
        }
        otherFormRef.value.validate((result: any) => {
            if (!result) return reject(result);
            const welcome = {
                is_staff: 0,
                // content: WelcomeRef.value.formData.materialResult.welcome_info.welcome_text,
                // media_content: WelcomeRef.value.formData.materialResult.welcome_info.welcome_material,
                // local_link: WelcomeRef.value.formData.materialResult.welcome_info.welcome_material,
                // local_content: WelcomeRef.value.formData.materialResult.welcome_info.welcome_material,
                welcome_info: welcome_info // 使用欢迎语组件数据
            };
            resolve(handleOtherConfig(formData, fileList, welcome, uploadList));
        });
    });
};
const setDetailInfo = (detailInfo: any) => {
    const formConfigData: any = handleOtherConfigToView(detailInfo);
    Object.assign(formData, formConfigData);
    const { link_img_url, link_img_file_id } = detailInfo.share_setting;
    fileList.splice(0, fileList.length, { url: link_img_url, code: link_img_file_id });
    const redirect = detailInfo.submit_settings?.redirect || {};
    formData.submit_settings.collect_type = !!formData.submit_settings.collect_limit;
    formData.submit_settings.collect_limit = formData.submit_settings.collect_limit
        ? formData.submit_settings.collect_limit
        : '';
    detailInfo.ads && uploadList.splice(0, uploadList.length, { url: detailInfo.ads });
    // 添加员工才有欢迎语
    if (redirect.submit_redirect_type === 1) {
        const welcomeInfo: any = redirect.welcome?.welcome_info;
        formData.submit_settings.redirect.welcome = welcomeInfo?.welcome_text;
        defaultMaterialContentData = initMaterialData(redirect.welcome?.welcome_info?.welcome_material || []);
    }
};

/**
 * 1-图文 2-文字 3-视频 4-音频 5-图片
 * @param {*} type 1-name 2-imgUrl
 * @param {*} article
 */
const getArticleTypeName = (type: number, article: any) => {
    const articleType = article.article_type;
    const list = [
        { name: '', code: 1, iconUrl: '/static/file/official.png' },
        { name: '', code: 2, iconUrl: '/static/file/text.png' },
        { name: '视频', code: 3, iconUrl: '/static/file/mov.png' },
        { name: '音频', code: 4, iconUrl: '/static/file/mp3.png' },
        { name: '图片', code: 5, iconUrl: '/static/file/pic.png' }
    ];
    const info: any = list.find(el => el.code == articleType) || {};
    if (type == 1) {
        return info.name;
    } else if (type == 2) {
        if (articleType == 1) {
            return article.link_share_image;
        } else {
            return info.iconUrl;
        }
    }
};
const validateField = val => {
    otherFormRef?.value?.validateField(val);
};
/**修改提交次数 */
const changeNum = (val: any) => {
    if (val == 2) {
        formData.submit_settings.limit_value = '';
    } else {
        formData.submit_settings.limit_value = 1;
        validateField('submit_settings.limit_type');
    }
};
/**修改收集数量限制 */
const changeLimit = val => {
    formData.submit_settings.collect_limit = '';
};
const dialogPreviewVisible = ref(false);
const affixRef = ref();
defineExpose({
    getParams,
    setDetailInfo
});
</script>

<style lang="scss" scoped>
@import './scss/Form';
@import './scss/OtherForm';
</style>
